//
//  WTFDRightTableView.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/4/18.
//  Copyright © 2019 SanYi. All rights reserved.
//

#import "WTFDRightTableView.h"

@interface WTFDRightTableView ()

@property (strong, nonatomic) SYNoLabel *nolab;
@property (strong, nonatomic) NSMutableArray *dataListArr;

@end

@implementation WTFDRightTableView

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    [self.tableView registerClass:[WTFDRightTableViewCell class] forCellReuseIdentifier:@"WTFDRightTableViewCell"];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.dataListArr = [[NSMutableArray alloc] init];
    //_nolab = [[SYNoLabel alloc] initWithNameStr:@"" contView:self.tableView];
    
//    [_nolab mas_remakeConstraints:^(MASConstraintMaker *make) {
//       
//    }];
    _nolab = [[SYNoLabel alloc] initWithNameStr:@"" contView:self.view];
    _nolab.backgroundColor = [UIColor redColor];
//    [_nolab mas_remakeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.view.mas_top).offset(100);
//        make.left.equalTo(self.view.mas_left).offset(0);
//        make.width.mas_equalTo(410);
//        make.height.mas_equalTo(540);
//    }];
    _nolab.frame = CGRectMake(0, 0, 410, 540);
}

- (void)requestNotData {
    self.dataListArr = [NSMutableArray new];
    self.nolab.hidden = NO;
    [self.tableView reloadData];
}

- (void)requestData:(SYWenTiFuDaoModel *)model {
    __weak typeof(self) weakSelf = self;
    [MBProgressHUD mj_showLoading];
    [SYRequestAPI fd_requestQuestionDetailQuestionId:model.questionId success:^(NSMutableArray *listArr) {
        [MBProgressHUD mj_hideHUD];
        weakSelf.dataListArr = listArr;
        [self.tableView reloadData];
        
    } fail:^(NSError *error) {
        [MBProgressHUD mj_hideHUD];
        weakSelf.nolab.hidden = NO;
    }];
}
- (void)requestDataArr:(NSMutableArray *)dataArr {
    self.dataListArr = dataArr;
    if (dataArr.count == 0) {
        self.tableView.hidden = YES;
        self.nolab.hidden = NO;
    } else {
        self.tableView.hidden = NO;
        self.nolab.hidden = YES;
        [self.tableView reloadData];
    }
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataListArr.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 271*fh+30;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    SYWenTiDetailsModel *details = self.dataListArr[indexPath.row];
    WTFDRightTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WTFDRightTableViewCell" forIndexPath:indexPath];
    if (!cell) {
        cell = [[WTFDRightTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"WTFDRightTableViewCell"];
    }
    if (indexPath.row == 0) {
        cell.topLineView.hidden = YES;
        cell.circleImageView.image = [UIImage imageNamed:@"top_circle_image"];
    }else{
        cell.topLineView.hidden = NO;
        cell.circleImageView.image = [UIImage imageNamed:@"circle_buke"];
    }
    
     cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    cell.titleLabel.text = details.time;
    cell.timeLabel.text = details.interval;
    [cell.headerImageView sd_setImageWithURL:[NSURL URLWithString:details.headImg] placeholderImage:[UIImage imageNamed:@"fudao_wentitx"]];
    cell.nameLabel.text = details.name;
    cell.detailLabel.text = details.title;
    [cell.contentBackImage sd_setImageWithURL:[NSURL URLWithString:details.cover] placeholderImage:[UIImage imageNamed:@"fudao_wentibg"]];
    cell.backgroundColor = [UIColor whiteColor];
    return cell;
}

// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}



// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}



// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}



// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
